package com.排序.排序基础;

public class 计数排序 {
    public static void sort(int[] a) {
        int max = a[0];
        int min = a[0];
        for (int i : a){
            if (i > max){
                max = i;
            }
            if (i < min){
                min = i;
            }
        }
        int[] count = new int[max - min + 1];

        for(int v : a){
            count[v - min]++;
        }

        int k =0;
        for(int i = 0;i < count.length;i++){
            while (count[i] > 0){
                a[k++] = i+min;
                count[i]--;
            }
        }
    }
}
